import 'package:chop/common/MessageUtils.dart';
import 'package:chop/view/home/home_page.dart';
import 'package:chop/widgets/appBar.dart';
import 'package:chop/widgets/loadingDialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:get/get.dart';

class PoliPay extends StatefulWidget {
  final String url;

  const PoliPay({Key key, this.url}) : super(key: key);
  @override
  _PoliPayState createState() => _PoliPayState();
}

class _PoliPayState extends State<PoliPay> {
  String url;

  @override
  void initState() {
    this.url = widget.url;
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    return WebviewScaffold(
      url: url,
      appBar: BaseViewBar(
        childView: BaseTitleBar(
          "POLIPay",
          leftIcon: Icons.clear,
          leftClick: (){
            print("关闭支付----------------------");
            flutterWebviewPlugin.hide();
            showDialog<Null>(
              context: context, //BuildContext对象
              barrierDismissible: false,
              builder: (BuildContext context) {
                return AlertDia(
                  //调用对话框
                  text: '放弃支付',
                  yes: (){
                    flutterWebviewPlugin.close();
                    Get.off(homePage());
                  },
                  no: (){
                    flutterWebviewPlugin.show();
                    Get.back();
                  },
                );
              },
            );
          },
        ),
        preferredSize: Size.fromHeight(50.00),
      ),
      withJavascript: true,
      withLocalStorage: true,
      withZoom: true,
    );
  }
}
